package com.itheima.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.dao.FoodSettingDao;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.pojo.CheckItem;
import com.itheima.pojo.FoodSetting;
import com.itheima.pojo.OrderSetting;
import com.itheima.service.FoodSettingService;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author ZhaoShengChao
 * @create 2021/8/7 21:45
 */
@Service(interfaceClass=FoodSettingService.class)
@Transactional
public class FoodSettingServiceImpl implements FoodSettingService {


    @Autowired
    private FoodSettingDao foodSettingDao;

    /**
     * 文件上传
     * @param foodSettings
     */
    @Override
    public void add(List<FoodSetting> foodSettings) {
        if (foodSettings != null&&foodSettings.size() > 0) {

            for (FoodSetting foodSetting : foodSettings) {
                foodSettingDao.add(foodSetting);
            }
        }
    }

    /**
     * 单个文件新增
     * @param foodSetting
     */
    @Override
    public void add(FoodSetting foodSetting) {
         foodSettingDao.add(foodSetting);
    }

    @Override
    public PageResult pageQuery(QueryPageBean queryPageBean) {
        //当前页
        Integer currentPage = queryPageBean.getCurrentPage();
        //每页显示几条数据
        Integer pageSize = queryPageBean.getPageSize();
        //查询条件
        String queryString = queryPageBean.getQueryString();

        //分页助手插件
        PageHelper.startPage(currentPage,pageSize);

        Page<FoodSetting> list = foodSettingDao.findByCondition(queryString);

        //总条数
        long total = list.getTotal();
        //全部数据
        List<FoodSetting> result = list.getResult();

        return new PageResult(total,result);
    }

    /**
     * 通过id删除数据
     * @param id
     */
    @Override
    public void deleteById(Integer id) {
        foodSettingDao.deleteById(id);
    }

    /**
     * 编辑数据
     * @param foodSetting
     */
    @Override
    public void edit(FoodSetting foodSetting) {
        foodSettingDao.edit(foodSetting);
    }
}
